package com.testlio.assignment.controller;

import com.testlio.assignment.dto.IssueComparisonDTO;
import com.testlio.assignment.dto.IssueRevisionDTO;
import com.testlio.assignment.service.IssueRevisionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/issues/{issueId}/revisions")
@AllArgsConstructor
@Tag(name = "Issue Revisions", description = "Issue revision management APIs")
public class IssueRevisionController {
    private final IssueRevisionService revisionService;

    @GetMapping
    public ResponseEntity<List<IssueRevisionDTO>> getRevisions(@PathVariable Integer issueId) {
        return ResponseEntity.ok(revisionService.getRevisions(issueId));
    }

    @GetMapping("/compare")
    @Operation(summary = "Compare two revisions of an issue")
    public ResponseEntity<IssueComparisonDTO> compareRevisions(
            @PathVariable Integer issueId,
            @RequestParam Integer revisionA,
            @RequestParam Integer revisionB) {
        return ResponseEntity.ok(revisionService.compareRevisions(issueId, revisionA, revisionB));
    }
}
